home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntinc20 / varargs.h < prev    next >
C/C++ Source or Header  |  1992-05-15  |  2KB  |  73 lines

  1. #ifndef _VARARGS_H
  2. #define _VARARGS_H
  3.  
  4. /* in case stdarg.h got included by a header file */
  5. #ifdef va_start
  6. #undef va_start
  7. #undef va_end
  8. #undef va_dcl
  9. #undef va_alist
  10. #undef va_list
  11. #endif
  12.  
  13. #ifndef _COMPILER_H
  14. #include <compiler.h>
  15. #endif
  16.  
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21. #ifndef __GNUC__
  22. /* I'm not sure this is right.  These apparently are all supposed to be
  23.    defines; doesn't seem to make much sense to make them functions.
  24.    There may be some missing from this list; these are the ones I found
  25.    by grepping around in code...
  26. */
  27.  
  28. /* a va_list is a list of random frobules */
  29. typedef __VA_LIST__ va_list;
  30.  
  31. /* the address of the list??? don't we already have that???  C programmers
  32.    pick the wierdest times to start worrying about abstractions! */
  33. #define va_start(args) args = (va_list) &va_alist
  34.  
  35. /* is this supposed to do anything??? */
  36. #define va_end(args)
  37.  
  38. /* This is apparently a general purpose accessor, used for storing, as 
  39.    well as snarfing.  This is the only way I could think of to make it
  40.    work that way.  Please, somebody, re-write this! */
  41. #define va_arg(args, elt_type) ((elt_type * ) ((args) += sizeof(elt_type)))[-1]
  42.  
  43. #define va_dcl    int va_alist;
  44.  
  45. #else
  46.  
  47. /* These macros implement traditional (non-ANSI) varargs
  48.    for GNU C.  */
  49.  
  50. #define va_alist  __builtin_va_alist
  51. #define va_dcl    int __builtin_va_alist;
  52. #define va_list   __VA_LIST__
  53.  
  54. #define va_start(AP)  AP=(char *) &__builtin_va_alist
  55. #define va_end(AP)
  56.  
  57. #define __va_rounded_size(TYPE)  \
  58.   (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
  59.  
  60. #define va_arg(AP, TYPE)                        \
  61.  (AP += __va_rounded_size (TYPE),                    \
  62.   ((TYPE *) AP)[-1])
  63.  
  64. /* thanks dale! */
  65.  
  66. #endif /* __GNUC__ */
  67.  
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71.  
  72. #endif /* _VARARGS_H */
  73.